//
//  ST_ExchangeByIncomeSuccessController.swift
//  btvideo
//
//  Created by mac on 2020/10/15.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SwiftyJSON
import SwiftyUserDefaults

class ST_ExchangeByIncomeSuccessController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        view.backgroundColor = .clear
        
        view.addSubview(root_view)
        root_view.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.bottom.equalToSuperview().offset(15)
            make.height.equalTo(30+439+BTSafeAreaBottom)
        }
        
        view.addSubview(close_view)
        close_view.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.bottom.equalTo(root_view.snp.top)
        }
        
        
        root_view.addSubview(center_image_view)
        center_image_view.snp.makeConstraints { (make) in
            make.width.height.equalTo(76)
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(25)
        }
        
        root_view.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(131)
            make.height.equalTo(25)
        }
        root_view.addSubview(content_label)
        content_label.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(166)
            make.height.equalTo(21)
        }
        
        root_view.addSubview(item0)
        root_view.addSubview(item1)
        root_view.addSubview(item2)
        root_view.addSubview(item3)
        
        item0.snp.makeConstraints { (make) in
            make.right.left.equalToSuperview()
            make.height.equalTo(21+15)
            make.top.equalTo(content_label.snp.bottom).offset(23)
        }
        
        item1.snp.makeConstraints { (make) in
            make.right.left.equalToSuperview()
            make.height.equalTo(item0)
            make.top.equalTo(item0.snp.bottom).offset(6)
        }
        
        item2.snp.makeConstraints { (make) in
            make.right.left.equalToSuperview()
            make.height.equalTo(item0)
            make.top.equalTo(item1.snp.bottom).offset(6+3)
        }
        
        item3.snp.makeConstraints { (make) in
            make.right.left.equalToSuperview()
            make.height.equalTo(item0)
            make.top.equalTo(item2.snp.bottom).offset(6)
        }
        
        root_view.addSubview(confirm_btn)
        confirm_btn.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(item3.snp.bottom).offset(30-8)
            make.width.equalTo(345)
            make.height.equalTo(44)
        }
        
        item0.content_label.text = json["order_no"].stringValue
        item1.content_label.text = json["apply_time"].stringValue
        item2.content_label.text = json["goods_tip"].stringValue
        item3.content_label.text = json["use_integral"].stringValue
        
    }
    
    
    var json = JSON.null{
        didSet{
            ST_BTUserInfoManager.shared.modify_sweet_income(value: json["income"].doubleValue, outValue: json["income_out"].doubleValue)
        }
    }
    
    //    MARK: - Properties
    fileprivate lazy var root_view:UIView = {
        let control = UIView()
        control.backgroundColor = UIColor.white
        control.cornerRadius = 15
        return control
    }()
    
    fileprivate lazy var close_view:UIControl = {
        let control = UIControl()
        //            control.addTarget(self, action: #selector(close_handle), for: UIControl.Event.touchUpInside)
        return control
    }()
    
    
    fileprivate lazy var center_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = .scaleAspectFill
        control.image = ST_ImageUtils.imageName("exchange选中_icon")
        return control
    }()
    
    fileprivate lazy var titleLabel:UILabel = {
        let control = UILabel.init()
        control.text = "兑换成功"
        control.textColor = UIColor(hexString: "#333333")
        control.textAlignment = .center
        control.font = UIFont.systemFont(ofSize: 18, weight: UIFont.Weight.medium)
        return control
    }()
    
    fileprivate lazy var content_label:UILabel = {
        let control = UILabel.init()
        control.text = "审核通过后将会自动到账，请耐心等待"
        control.textColor = UIColor(hexString: "#ACB4C0")
        control.textAlignment = .center
        control.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.regular)
        return control
    }()
    
    fileprivate lazy var item0:ST_ExchangeByIncomeSuccessCell = {
       let control = ST_ExchangeByIncomeSuccessCell()
        control.titleLabel.text = "兑换ID:"
        return control
    }()
    
    fileprivate lazy var item1:ST_ExchangeByIncomeSuccessCell = {
       let control = ST_ExchangeByIncomeSuccessCell()
        control.titleLabel.text = "申请时间:"
        return control
    }()
    
    fileprivate lazy var item2:ST_ExchangeByIncomeSuccessCell = {
       let control = ST_ExchangeByIncomeSuccessCell()
        control.titleLabel.text = "兑换物品:"
        return control
    }()
    
    fileprivate lazy var item3:ST_ExchangeByIncomeSuccessCell = {
       let control = ST_ExchangeByIncomeSuccessCell()
        control.titleLabel.text = "消耗\(Defaults[.PandaStr]):"
        return control
    }()
    
    fileprivate lazy var confirm_btn:UIButton = {
                
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.semibold)
        control.setTitle("确定", for: UIControl.State.normal)
        control.setTitleColor(UIColor.white, for: UIControl.State.normal)
        control.setBackgroundImage(UIImage.init(color: UIColor.init(hex: 0xFEC207)!, size: CGSize.init(width: 1, height: 1)), for: UIControl.State.selected)
        control.setBackgroundImage(UIImage.init(color: UIColor.init(hex: 0xDFE3E9)!, size: CGSize.init(width: 1, height: 1)), for: UIControl.State.normal)
        control.cornerRadius = 22
        control.isSelected = true
//      control.semanticContentAttribute = .forceRightToLeft
        control.addTarget(self, action: #selector(confirm_handle), for: UIControl.Event.touchUpInside)
        return control
    }()
    
    @objc fileprivate func confirm_handle(){
        
        goback_previous_controller()
        
    }
}



//MARK: - Cell
class ST_ExchangeByIncomeSuccessCell: UIControl {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.addSubview(titleLabel)
        self.addSubview(content_label)
        
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(15)
            make.centerY.equalToSuperview()
        }
        
        content_label.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(90)
            make.centerY.equalToSuperview()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var titleLabel:UILabel = {
        let control = UILabel.init()
        control.textColor = UIColor(hexString: "#333333")
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.regular)
        return control
    }()
    
    lazy var content_label:UILabel = {
        let control = UILabel.init()
        control.textColor = UIColor(hexString: "#333333")
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.regular)
        return control
    }()
}
